Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) _
    As Long
Private Const CSC_NAVIGATEFORWARD As Integer = 1
Private Const CSC_NAVIGATEBACK As Integer = 2

Private Const CB_FINDSTRING As Long = &H14C

Dim mbDontNavigateNow As Boolean
Private Minimized As FormWindowStateConstants

Public Sub ComboAutoComplete(ByRef SourceCtl As VB.ComboBox, _
    ByRef KeyAscii As Integer, ByRef LeftOffPos As Long)
  Dim iStart As Long
  Dim sSearchKey As String
  
  With SourceCtl
    'If text entered so far matches item(s) in the list, use autocomplete
    Select Case Chr$(KeyAscii)
      Case vbBack
        'Let backspace characters process as usual; otherwise try to match text
      Case Else
        If Chr$(KeyAscii) <> vbBack Then
          .SelText = Chr$(KeyAscii)
          
          iStart = .SelStart
          
          If LeftOffPos <> 0 Then
            .SelStart = LeftOffPos
            iStart = LeftOffPos
          End If
          
          sSearchKey = CStr(Left$(.Text, iStart))
          .ListIndex = SendMessage(.hWnd, CB_FINDSTRING, -1, _
              ByVal CStr(Left$(.Text, iStart)))
          
          If .ListIndex = -1 Then
            LeftOffPos = Len(sSearchKey)
          End If
          
          .SelStart = iStart
          .SelLength = Len(.Text)
          LeftOffPos = 0
          
          KeyAscii = 0
        End If
    End Select
  End With
End Sub

Private Sub brwWebBrowser_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    
    'URL = cboAddress.Text
    
    'If cboAddress.Text = "www.myspace.com" Or cboAddress.Text = "http://www.myspace.com" Or cboAddress.Text = "http://myspace.com" Or cboAddress.Text = "myspace.com" Then
        'MsgBox "Access Denied! " & URL & " is blocked for bad stuff.", vbCritical
        'Cancel = True
        'Me.Caption = "Access Denied!" & " - My Web Browser" & Space(1) & App.Major & "." & App.Minor & "." & App.Revision
    'ElseIf cboAddress.Text = "www.philywily.com" Or cboAddress.Text = "http://philywily.com" Or cboAddress.Text = "http://www.philywily.com" Or cboAddress.Text = "philywily.com" Then
        'MsgBox "Access Denied! " & URL & " is blocked for going through websites.", vbCritical
        'Cancel = True
        'Me.Caption = "Access Denied!" & " - My Web Browser" & Space(1) & App.Major & "." & App.Minor & "." & App.Revision
    'End If
End Sub

Private Sub brwWebBrowser_DownloadComplete()
    On Error Resume Next
    Me.Caption = brwWebBrowser.LocationName & " - My Web Browser" & Space(1) & App.Major & "." & App.Minor & "." & App.Revision
End Sub

Private Sub brwWebBrowser_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    'Dim i As Integer
    'Dim bFound As Boolean
    
    'Me.Caption = brwWebBrowser.LocationName & " - My Web Browser" & Space(1) & App.Major & "." & App.Minor & "." & App.Revision
    'For i = 0 To cboAddress.ListCount - 1
        'If cboAddress.List(i) = brwWebBrowser.LocationURL Then
            'bFound = True
            'Exit For
        'End If
    'Next i
    'mbDontNavigateNow = True
    'cboAddress.AddItem brwWebBrowser.LocationURL, 0
    'cboAddress.ListIndex = 0
    'mbDontNavigateNow = False
End Sub

Private Function IsPopupWindow() As Boolean
    On Error Resume Next
    If brwWebBrowser.Document.activeElement.tagName = "BODY" Or brwWebBrowser.Document.activeElement.tagName = "IFRAME" Then
        IsPopupWindow = True
    Else
        IsPopupWindow = False
    End If
End Function

Private Sub brwWebBrowser_NewWindow2(ppDisp As Object, Cancel As Boolean)
    On Error Resume Next
    Dim frmNW As frmApp
    
    Cancel = IsPopupWindow
    
    Set frmNW = New frmApp
    frmNW.brwWebBrowser.RegisterAsBrowser = True
    Set ppDisp = frmNW.brwWebBrowser.object
    frmNW.Show
    frmNW.Caption = frmWebBrowser.brwWebBrowser.LocationName & " - My Web Browser" & Space(1) & App.Major & "." & App.Minor & "." & App.Revision
    Popups.Visible = True And False
End Sub
Private Function Popups() As frmApp
    Dim frmAds As frmApp
    Dim ppDisp As Object
    Dim Cancel As Boolean
    
    If Cancel = False Then
        Set frmAds = New frmApp
        Set ppDisp = frmAds.brwWebBrowser.object
        frmAds.Visible = False And False
        Unload frmAds
    End If
End Function

Private Sub Form_Load()
    brwWebBrowser.Silent = True
    Timer1.Interval = 1000
    stbStatus.Panels(2).Text = Time
    stbStatus.Panels(3).Text = Date
End Sub

Private Sub Form_Resize()
    Dim laststate As String

    laststate = Me.WindowState
    If Me.WindowState <> vbMinimized Then
       brwWebBrowser.Height = Me.Height - 2400
       brwWebBrowser.Width = Me.Width - 100
    End If
End Sub

Private Sub brwWebBrowser_StatusTextChange(ByVal Text As String)
    stbStatus.Panels(1).Text = Text
End Sub